{% extends "BluehouseappWebBundle:Backend/Admin/layout:layout.html.twig" %}
{% from 'BluehouseappWebBundle:Macros:misc.html.twig'  import pagination %}
{% import 'BluehouseappWebBundle:Macros:buttons.html.twig' as buttons %}


{% block title %}
    分类管理
{% endblock %}
{% block body -%}
    {% set entities=categories %}
    <div class="page-header">
        <h2>分类管理 <small></small></h2>
    </div>
    <ol class="breadcrumb clearfix">
        <div class="clearfix">
            <div class="pull-left">
                {{ buttons.create(path('bluehouseapp_category_new')) }}
            </div>
        </div>
    </ol>

    {{ pagination(entities) }}
    <table class="table  table-striped table-hover table-condensed">
        <thead>
            <tr>
                <th>{{bluehouse_resource_sort('name', '分类名称') }}</th>
                <th>{{bluehouse_resource_sort('no', '显示序号') }}</th>
                <th>{{bluehouse_resource_sort('enabled', '状态') }}</th>
                <th>节点</th>
                <th>最后修改时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        {% for entity in entities %}
            <tr>

                <td>
                    <a href="{{ path('bluehouseapp_category_show', { 'id': entity.id }) }}">
                    {{ entity.name }}
                    </a>
                </td>

                <td>{{ entity.no }}</td>
                <td>
                    {% if entity.enabled %}
                        <span class="label label-success">正常</span>
                    {% else %}
                        <span class="label label-danger">已禁用</span>
                    {% endif %}
                </td>
                <td>
                    {% if entity.nodes %}
                    {% set nodes=entity.nodes %}
                    {% for node in nodes %}
                        {% if node.status %}
                            {% if node.enabled %}
                            {{ node.name }}
                            {% endif %}
                        {% endif %}
                    {% if loop.last %}
                    {% else %}
                        ,
                    {% endif %}

                    {% endfor %}
                    {% endif %}
                </td>
                <td>{% if entity.modified %}{{ entity.modified|date('Y-m-d H:i:s') }}{% endif %}</td>
                <td>
                <ul>

                    <li>
                        {{ buttons.edit(path('bluehouseapp_category_edit', { 'id': entity.id })) }}
                    </li>


                    <li>
                        {% if entity.enabled %}
                            {{ buttons.disable(path('bluehouseapp_category_disable',{id:entity.id})) }}

                        {% else %}
                            {{ buttons.enable(path('bluehouseapp_category_enable',{id:entity.id})) }}
                        {% endif %}
                    </li>
                    <li>
                        {{ buttons.delete(path('bluehouseapp_category_delete',{id:entity.id})) }}
                    </li>
                </ul>
                </td>
            </tr>
        {% endfor %}
        </tbody>

    </table>
    {{ pagination(entities) }}

    {% endblock %}
